#include "login.h"
#include "cleanScan.h"
#include "cronistaMenu.h"
#include <string.h>
#include <stdlib.h>
void login(){
	struct UserVars *userData;
	loadUsers("data/Usuarios.txt",&userData);
	int loggedIn=0;
	char login[10],password[10];
	//while(!loggedIn){
		system("clear");
		printf("Username:\n");
		fgets(login,sizeof(login),stdin);
		cleanString(login);
		printf("\nPassword:");
		fgets(password,sizeof(password),stdin);
		cleanString(password);
		int userIndex=-1;
		for(int i=0;i<usercount && !loggedIn;i++){
			if(strcmp(login,userData[i].user) == 0){
				if(strcmp(password,userData[i].password) == 0){
					loggedIn=1;
					userIndex=i;
				}
			}
		}
		if(loggedIn){
			if(!strcmp(userData[userIndex].userType,"participante")){
				participantMenu(userData[userIndex]);
			}
			if(!strcmp(userData[userIndex].userType,"administrador")){
				//adminMenu(userData[userIndex]);
			}
			if(!strcmp(userData[userIndex].userType,"cronista")){
				cronistaMenu(userData[userIndex]);
			}
		}
		else{
			printf("Invalid username or password\n");
		}
//	}
}
